package com.iss.yunpan.controller;

import com.iss.yunpan.entity.Users;
import com.iss.yunpan.service.UserService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;



@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("changePassword")
    public String changePassword(){
        return "changePassword";
    }

    @PostMapping("changePassword")
    public String changePassword(Model model, HttpSession session, String password){
        try {
            Users user = (Users)session.getAttribute("users");
            user.setPassword(password);
            userService.changePassword(user);
            model.addAttribute("users",user);
            session.setAttribute("users",user);
            return "main"; //
        }catch(Exception e){
            e.printStackTrace();
            return "main"; //
        }
    }
}
